package niuke;

/**
 * 二叉搜索树转换为双向链表
 */
public class Solution5 {
    TreeNode head = null;
    TreeNode prev = null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree == null) return null;
        Convert( pRootOfTree.left);
        if( prev == null) {
            head = pRootOfTree;
            prev = pRootOfTree;
        } else {
            prev.right = pRootOfTree;
            pRootOfTree.left = prev;
            prev = pRootOfTree;
        }
        Convert(pRootOfTree.right);
        return head;
    }
}